package loginRegisterAction;

import java.util.List;

import loginRegisterDao.LoginRegisterInfo;

import com.opensymphony.xwork2.ActionSupport;

import PO.UserInfoPO;
/**
 * �û���¼Action��
 * @author Administrator
 *
 */
public class LoginAction extends ActionSupport{

    private String userName;
    private String password;
    private String message="error";
    private List list;
    
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    /**
     * �û���¼����֤����ʾ������Ϣ
     */
    public void validate(){
        if(this.getUserName()==null||this.getUserName().length()==0){
            addFieldError("userName", "�û�������Ϊ��!");
        }else{
            LoginRegisterInfo info= new LoginRegisterInfo();
            list=info.queryInfo("userName", this.getUserName());
            if(list.size()==0){
                addFieldError("userName", "账号错误");
            }else{
                UserInfoPO ui=new UserInfoPO();
                for(int i=0;i<list.size();i++){
                    ui=(UserInfoPO) list.get(i);
                    if(this.getUserName().equals(ui.getUserName())){
                        if(ui.getPassword().equals(this.getPassword())){
                            message="success";
                        }else{
                            addFieldError("password", "��������ȷ���û����룡");
                        }
                    }
                }
            }
        }
    }
    
    public String execute() throws Exception{
        return message;
    }
    
}